<?php
    require_once("config.php");
    
    $hash = $_GET['hash'];
    $query = "SELECT * FROM guests WHERE reset_hash='$hash';";
    $row = DBM::FetchRow($query);
        
    Functions::PrintHeader("Password Reset");
    
    // if it's a valid user and the bot validation succeeded
    if (isset($row) && DBM::CountRows($query) === 1) {
        $tmppassword = substr(md5(microtime()),0,8);
        $update = array("password"=>md5($tmppassword), "reset_hash" => "", "password_plaintext" => $tmppassword);
	$update_query = QueryTools::CreateQuery($update,'guests','update',$row['id']);
        DBM::Execute($update_query);
        
        MailManager::SendResetPasswordComplete($row['email'],$row['id']);
        SuccessMessage::Show("Password Reset","Your password has been reset.  Your new password has been E-Mailed to $row[email].");
    }
    else {
        ErrorMessage::Show("Error Resetting Password","There was an error resetting your password.");
    }
    
    Functions::PrintFooter();
?>
